package org.youyee.game.utils
{
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.geom.Point;
	
	import org.youyee.game.pathFinding.PathNode;

	/**
	 * 此类用于绘制和地图相关的图形的工具类，比如绘制一个节点的图形 
	 * @author youyeelu
	 * 
	 */	
	public class MapGraphicUtil
	{
		/**
		 * 地板的宽度的一半
		 */		
		public static var WIDTH_VALUE:Number = 35;
		/**
		 * 地板的高度的一半 
		 */		
		public static var HEIGHT_VALUE:Number = 17.5;
		
		/**
		 * 绘制一个节点 
		 * @param color 线框需要的颜色
		 * @param pathNode 需要被绘制的节点
		 * @param shape 图形对象
		 * @param lineAlpha 线条的透明度
		 * @param fillAlpha 填充的透明度
		 * 
		 */		
		public static function drawPathNode(color:uint, pathNode:PathNode, shape:Sprite, lineAlpha:Number=1, fillAlpha:Number=0.5):void
		{
			if (pathNode)
			{
				var point:Point = PositionCalculator.getPositionByPathNode(pathNode);
				
				shape.graphics.lineStyle(1, color, 1);
				shape.graphics.beginFill(color, 0.5);
				shape.graphics.moveTo(point.x - WIDTH_VALUE, point.y + HEIGHT_VALUE);
				shape.graphics.lineTo(point.x, point.y);
				shape.graphics.lineTo(point.x + WIDTH_VALUE, point.y + HEIGHT_VALUE);
				shape.graphics.lineTo(point.x, point.y + 2 * HEIGHT_VALUE);
				shape.graphics.lineTo(point.x - WIDTH_VALUE, point.y + HEIGHT_VALUE);
				shape.graphics.endFill();
			}
		}
		
		/**
		 * 绘制路径 
		 * @param path 需要被绘制的路径
		 * @param color 线框颜色
		 * @param shape 图形对象
		 * @param lineAlpha 线条的透明度
		 * @param fillAlpha 填充的透明度
		 * 
		 */		
		public static function drawPath(path:Array, color:uint, shape:Sprite, lineAlpha:Number=1, fillAlpha:Number=0.5):void
		{
			var len:int = path.length;
			
			for (var i:int=0; i<len; ++i)
			{
				drawPathNode(color, path[i] as PathNode, shape, lineAlpha, fillAlpha);
			}
		}
	}
}